package com.hna.eking.AirlineServer.Exception;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileUploadBase.FileSizeLimitExceededException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import com.hna.eking.AirlineServer.Utils.ResponseSupport;

@ControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler{
	
	Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
	/**
     * 全局异常，会替代springsecurity的accessdeniedhandler来处理，有点问题，权限失败的处理器在其后处理。。。
     */
    @ExceptionHandler(value=MultipartException.class)  
    public @ResponseBody ResponseSupport<String> allExceptionHandler(
    		Exception exception) throws Exception  
    {  
       	logger.debug(exception.getMessage());
       	ResponseSupport<String> responseSupport = new ResponseSupport<String>();
		responseSupport.setCode(1007);
		responseSupport.setMessage("文件大小不能超过20MB！");
		return responseSupport;
    }  
    
}
